import Snap from 'snapsvg-cjs'
const changeColorTime = 200
const changePositionTime = 1000

/** 颜色变换动画
 *
 * @param {*} el 变化对象
 * @param {*} color 变换的颜色
 */
export function doColorAnimate(el, color) {
  el.animate({ fill: color }, changeColorTime)
}

/** 位置变换动画
 *
 * @param {*} el 变化的对象
 * @param {*} matrix 变化矩阵
 */
export function doPositionAnimate(el, matrix) {
  el.animate({ transform: matrix }, changePositionTime)
}

/** 获取模式对应的颜色
 *
 * @param {*} mode  模式
 * @returns  颜色字符
 */
export function getModeColor(mode) {
  let color = '#999'
  switch (mode) {
    case 1:
      color = '#67C23A'
      break
    case 2:
      color = '#0ff'
      break
    case 3:
      color = '#409EFF'
      break
    case 4:
      color = '#F56C6C'
      break
    case 5:
      color = '#E6A23C'
      break
    default:
      break
  }
  return color
}

/** 获取设备位置尺寸
 *
 * @param {Elememt} device 设备对象
 * @returns
 */
export function getDeviceAppearance(device) {
  // const margin = 45
  const x = device.node.x.baseVal.value
  const y = device.node.y.baseVal.value
  const width = device.node.width.baseVal.value
  const height = device.node.height.baseVal.value
  let length = 0
  let position = null
  // if (width > height) {
  // length = height - margin * 2
  length = 137
  position = { x: x + width / 2 - length / 2, y: y + height / 2 - length / 2 }
  // position = { x: x + width / 2 - length / 2, y: y + margin }
  // } else {
  //   // length = width - margin * 2
  //   length = 137
  //   // position = { x: x + margin, y: y + height / 2 - length / 2 }
  //   position = { x: x + width / 2 - length / 2, y: y + height / 2 - length / 2 }

  // }
  return {
    position,
    size: 137
  }
}
export async function initSvg() {

}
